home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ListLink / ListLink.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  6.7 KB  |  262 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Choice;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.FlowLayout;
  8. import java.awt.event.ItemEvent;
  9. import java.awt.event.ItemListener;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.net.URLEncoder;
  15. import java.util.EventObject;
  16.  
  17. public class ListLink extends Applet implements MouseListener, ItemListener {
  18.    private Thread thread;
  19.    private String[] url;
  20.    private String[] text;
  21.    private String target;
  22.    private Color backColor;
  23.    // $FF: renamed from: wi int
  24.    private int field_0;
  25.    // $FF: renamed from: he int
  26.    private int field_1;
  27.    private int n_link = 1;
  28.    // $FF: renamed from: c java.awt.Choice
  29.    private Choice field_2;
  30.    private String statusBarText;
  31.    private AudioClip sound;
  32.    private AudioClip clicSound;
  33.    private boolean loopSound;
  34.    private Color enterBackColor;
  35.  
  36.    public String getAppletInfo() {
  37.       return "Name: ListLink\r\nAuthor: Taiji Software\r\n";
  38.    }
  39.  
  40.    public ListLink() {
  41.       ((Component)this).addMouseListener(this);
  42.    }
  43.  
  44.    public void register() {
  45.       try {
  46.          URL u = new URL("http://www.taijisoftware.com");
  47.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  48.       } catch (Exception e) {
  49.          System.out.println(e);
  50.          ((Applet)this).stop();
  51.       }
  52.    }
  53.  
  54.    public void init() {
  55.       String codeBase = null;
  56.  
  57.       try {
  58.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  59.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  60.          codeBase = codeBase.toUpperCase();
  61.       } catch (Exception var9) {
  62.       }
  63.  
  64.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  65.          String regCode = ((Applet)this).getParameter("registration_code");
  66.          if (regCode == null) {
  67.             regCode = ((Applet)this).getParameter("reg_domain");
  68.             if (regCode == null) {
  69.                this.register();
  70.             } else {
  71.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  72.                   codeBase = "WWW." + codeBase;
  73.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  74.                   codeBase = codeBase.substring(4);
  75.                }
  76.  
  77.                char[] chars = new char[codeBase.length()];
  78.                codeBase.getChars(0, codeBase.length(), chars, 0);
  79.                String key = new String("haricot");
  80.                char[] chars2 = new char[key.length()];
  81.                key.getChars(0, key.length(), chars2, 0);
  82.  
  83.                for(int i = 0; i < codeBase.length(); ++i) {
  84.                   int j;
  85.                   if (i >= key.length()) {
  86.                      j = i - key.length() * (i / key.length());
  87.                   } else {
  88.                      j = i;
  89.                   }
  90.  
  91.                   chars[i] += chars2[j];
  92.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  93.                }
  94.  
  95.                String res = new String(chars);
  96.                if (!res.equalsIgnoreCase(regCode)) {
  97.                   this.register();
  98.                }
  99.             }
  100.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  101.             this.register();
  102.          }
  103.       }
  104.  
  105.       this.getParameters();
  106.       this.url = new String[this.n_link];
  107.       this.text = new String[this.n_link];
  108.  
  109.       for(int i = 0; i < this.n_link; ++i) {
  110.          this.url[i] = ((Applet)this).getParameter("link" + Integer.toString(i + 1));
  111.          this.text[i] = ((Applet)this).getParameter("text" + Integer.toString(i + 1));
  112.       }
  113.  
  114.       ((Container)this).setLayout(new FlowLayout());
  115.       this.field_2 = new Choice();
  116.       this.field_2.addItemListener(this);
  117.       this.field_2.setSize(this.field_0, this.field_1);
  118.  
  119.       for(int i = 0; i < this.n_link; ++i) {
  120.          this.field_2.addItem(this.text[i]);
  121.       }
  122.  
  123.       this.field_2.select(this.text[0]);
  124.       ((Container)this).add(this.field_2);
  125.       if (this.sound != null) {
  126.          if (this.loopSound) {
  127.             this.sound.loop();
  128.             return;
  129.          }
  130.  
  131.          this.sound.play();
  132.       }
  133.  
  134.    }
  135.  
  136.    public void getParameters() {
  137.       this.field_0 = ((Component)this).getSize().width;
  138.       this.field_1 = ((Component)this).getSize().height;
  139.       this.target = ((Applet)this).getParameter("target");
  140.       String s = ((Applet)this).getParameter("number");
  141.       if (s != null) {
  142.          this.n_link = Integer.parseInt(s);
  143.       }
  144.  
  145.       this.backColor = this.getColor("background_color");
  146.       ((Component)this).setBackground(this.backColor);
  147.       this.enterBackColor = this.getColor("enter_background_color");
  148.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  149.       s = ((Applet)this).getParameter("sound_name");
  150.       if (s != null) {
  151.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  152.       }
  153.  
  154.       s = ((Applet)this).getParameter("loop_sound");
  155.       if (s != null) {
  156.          if (s.equals("yes")) {
  157.             this.loopSound = true;
  158.          } else {
  159.             this.loopSound = false;
  160.          }
  161.       }
  162.  
  163.       s = ((Applet)this).getParameter("clic_sound_name");
  164.       if (s != null) {
  165.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  166.       }
  167.  
  168.    }
  169.  
  170.    public Color getColor(String param) {
  171.       String s = ((Applet)this).getParameter(param);
  172.       if (s != null) {
  173.          if (s.substring(0, 1).equals("#")) {
  174.             s = s.substring(1);
  175.             int i = Integer.parseInt(s, 16);
  176.             return new Color(i);
  177.          } else {
  178.             return null;
  179.          }
  180.       } else {
  181.          return null;
  182.       }
  183.    }
  184.  
  185.    public void itemStateChanged(ItemEvent evt) {
  186.       if (((EventObject)evt).getSource() instanceof Choice) {
  187.          if (this.clicSound != null) {
  188.             this.clicSound.play();
  189.          }
  190.  
  191.          int n = ((Choice)((EventObject)evt).getSource()).getSelectedIndex();
  192.  
  193.          try {
  194.             URL u = this.giveURL(this.url[n]);
  195.             String target = ((Applet)this).getParameter("target");
  196.             if (target == null) {
  197.                target = "_blank";
  198.             }
  199.  
  200.             ((Applet)this).getAppletContext().showDocument(u, target);
  201.          } catch (Exception err) {
  202.             System.err.println(err);
  203.          }
  204.       }
  205.    }
  206.  
  207.    public URL giveURL(String url) {
  208.       try {
  209.          if (url.toUpperCase().startsWith("HTTP")) {
  210.             return new URL(url);
  211.          } else if (url.toUpperCase().startsWith("FTP")) {
  212.             int p = url.indexOf(":");
  213.             int p2 = url.indexOf(":", p + 1);
  214.             if (p2 != -1) {
  215.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  216.             }
  217.  
  218.             p = url.indexOf("%40");
  219.             if (p != -1) {
  220.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  221.             }
  222.  
  223.             return new URL(url);
  224.          } else {
  225.             return new URL(((Applet)this).getCodeBase(), url);
  226.          }
  227.       } catch (MalformedURLException e) {
  228.          System.out.println(e);
  229.          return null;
  230.       }
  231.    }
  232.  
  233.    public void mouseClicked(MouseEvent e) {
  234.    }
  235.  
  236.    public void mouseEntered(MouseEvent e) {
  237.       if (this.statusBarText != null) {
  238.          ((Applet)this).showStatus(this.statusBarText);
  239.       }
  240.  
  241.       if (this.enterBackColor != null) {
  242.          ((Component)this).setBackground(this.enterBackColor);
  243.          ((Component)this).repaint();
  244.       }
  245.  
  246.    }
  247.  
  248.    public void mouseExited(MouseEvent e) {
  249.       if (this.enterBackColor != null) {
  250.          ((Component)this).setBackground(this.backColor);
  251.          ((Component)this).repaint();
  252.       }
  253.  
  254.    }
  255.  
  256.    public void mousePressed(MouseEvent e) {
  257.    }
  258.  
  259.    public void mouseReleased(MouseEvent e) {
  260.    }
  261. }
  262.